/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.exception.DataException;
import com.javabeans.*;
import com.util.*;
import com.model.*;
import com.db.*;
import java.sql.Connection;
import java.util.Calendar;
import java.util.List;
import javax.servlet.RequestDispatcher;

/**
 *
 * @author Administrador
 */
public class InfAcademicaEst extends HttpServlet {

    HttpServletRequest request;
    HttpServletResponse response;
    HttpSession session;
    String msg = "";
    
    private String PAGE = "";
    private static final String ERROR_PAGE = "WEB-INF/error.jsp";
    private static final String ERROR_AJAX = "WEB-INF/errorAjax.jsp";
    boolean isForward = true; // inicializamos con forward....
    Estudiante s_Estudiante = null;
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        this.request = request;
        this.response = response;
        session = request.getSession();
        int accion = Integer.parseInt(request.getParameter("accion"));
        if(session.getAttribute("s_estudiante") != null){
            s_Estudiante = (Estudiante)session.getAttribute("s_estudiante");
            try{
                switch(accion){
                    case 1 : indexInfoBiografica(); break;                           // accion = 1 = inicio de la informacion biografica
                    case 2 : verHorario(); break;                                    // accion = 2 = ver el formulario de horario
                    case 3 : showHorarios(); break;                                  // accion = 3 = muestra el horario del estudiante
                    case 4 : formKardex(); break;                                    // accion = 4 = muestra el formulario para ver kardex
                    case 5 : verKardex(); break;                                     // accion = 5 = muestra el kardes por carrera
                    case 6 : formEstadoInscrip(); break;                             // accion = 6 = muestra el formulario para ver el estado de inscripcion
                    case 7 : verEstadoInscrip(); break;                              // accion = 7 = muestra el estado de inscripcion de una gestion
                    default : System.out.println(" accion = "+accion+" no existe en Transacciones.java"); throw new DataException("accion = "+accion+" no existe en Transaccion.java");
                }
            }catch(DataException e){
                throw new ServletException(e);
            }
        }else
            PAGE = "web/index.jsp?msg=Indentifiquese. La Session no existe!";
        if(PAGE.length() > 0){
            if(isForward){
                RequestDispatcher dispatch = request.getRequestDispatcher(PAGE);
                dispatch.forward(request,response);
            }else{
                response.sendRedirect(PAGE);
            }
        }
    }
    
    private void indexInfoBiografica() throws DataException{// accion <-- 1
        PAGE = "WEB-INF/ESTUDIANTE/infoBiografica/infoBiografica.jsp";
    }
    
    private void verHorario() throws DataException{
        // accion = 2 = ver el formulario de horario
        Connection c = null;
        try{
            c = Conector.getConexion();
            GestionManager gmanager = ManagerFactory.getGestionManagerInstance(c);
            CarreraManager cmanager = ManagerFactory.getCarreraManagerInstance(c);
            List<Carrera> carreras = cmanager.getCarrerasPorEstBasic(s_Estudiante.getIdEstudiante());
            Calendar hoy = Calendar.getInstance();
            int year = hoy.get(Calendar.YEAR) - 15;
            request.setAttribute("carreras", carreras);
            request.setAttribute("gestiones", gmanager.getGestionesBasicByYear(year));
            PAGE = "WEB-INF/ESTUDIANTE/infoAcademica/verHorario/verHorario.jsp";
        }catch(DataException e){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> verHorarios() e: "+e.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> verHorarios() DataException "+e.getMessage());
            PAGE = ERROR_PAGE;
        }catch(Exception ex){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> verHorarios() ex: "+ex.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> verHorarios() Exception ex: "+ex.getMessage());
            PAGE = ERROR_PAGE;
        }finally{
            SqlManager.closeConexion(c);
        }
    }
    
    public void showHorarios()throws DataException{
        // accion = 3 = muestra el horario del estudiante
        PAGE = ""; // funcion ajax
        Connection c = null;
        try{
            int idFacultad = Integer.parseInt(request.getParameter("idFacultad"));
            int idCarrera = Integer.parseInt(request.getParameter("idCarrera"));
            String nomCarrera = request.getParameter("nomCarrera");
            int idGestion = Integer.parseInt(request.getParameter("idGestion"));
            String nomGestion = request.getParameter("nomGestion");
            
            c = Conector.getConexion();
            GrupoHorarioManager ghmanager = ManagerFactory.getGrupoHorarioManagerInstance(c);
            MateriaManager mmanager = ManagerFactory.getMateriaManagerInstance(c);
            DiaSemanaManager dsmanger = ManagerFactory.getDiaSemanaManagerInstance(c);
            PeriodoDiaManager pdmanager = ManagerFactory.getPeriodoDiaManagerInstance(c);
            HorarioManager hmanager = ManagerFactory.getHorarioManagerInstance(c);
            
            List<GrupoHorario> ghorarios = ghmanager.getHorariosGruposEst(idFacultad, idGestion, idCarrera, s_Estudiante.getIdEstudiante());
            List<PeriodoDia> periodosDia = pdmanager.getPeriodosDia(idFacultad);
            List<DiaSemana> diasSemana = dsmanger.getDiasHorario();
            List<Horario> horarios = hmanager.getHorariosBasic(idFacultad);
            
            // IMPRIMIMOS EL RESULTADO DE LA TRANSACCION
            PrintWriter out = response.getWriter();
            out.println("<h2 class='decorado'>Horarios Gesti&oacute;n ''"+nomGestion+"''</h2>");
            out.println("<div style='clear:left;color:#004080;margin:3px 0px 3px 0px;font-size: 10px;font-weight: bold'><b>CARRERA:</b> "+nomCarrera+"<br/></div>");
            out.println("<table class='tabla_decorado' style='width: 100%'>");
            int i = 0;
            int j = 0;
            int idD = 0;
            int idP = 0;
            int sizeD = diasSemana.size();
            boolean flag = false;
            String aux = "";
            if(periodosDia.size() > 0){
                for(PeriodoDia pd : periodosDia){
                    idP = pd.getIdPeriodoDia();
                    if(i == 0){
                        out.println("<thead>");
                        out.println("    <tr>");
                        out.println("        <th width='8%' class='th_decoradoRowspan'>&nbsp;</th>");
                        for(DiaSemana ds : diasSemana){
                            out.println("<th width='"+(92/sizeD)+"%' class='th_decoradoRowspan'>"+ds.getNombre()+"</th>");
                        }
                        out.println("    </tr>");
                        out.println("</thead>");
                        out.println("<tbody>");
                    }
                    j = 0;
                    // tr_decoradoRowspan
                    out.println("<tr class='tr_decoradoRowspan'>");
                    while(j < sizeD){
                        if(j == 0)
                            out.println("<td class='td_decoradoRowspan' align='center'>"+pd.getHoraIni()+" - "+pd.getHoraFin()+"</td>");
                        DiaSemana ds = (DiaSemana)diasSemana.get(j);
                        idD = ds.getIdDiaSemana();
                        flag = false;
                        aux = "";
                        for(Horario h : horarios){
                            if(idD == h.getIdDiaSemana() && idP == h.getIdPeriodoDia()){
                                flag = true;
                                for(GrupoHorario gh:ghorarios){
                                    if(idD == gh.getIdDiaSemana() && idP == gh.getIdPeriodoDia()){
                                        List<Materia> materias = mmanager.getMateriasPorGrupo(idGestion, gh.getIdGrupo());
                                        for(Materia m:materias){
                                            aux += m.getNombre()+" ("+m.getCarrera().getSigla()+")<br/>";
                                        }
                                        aux += "Doc.: "+gh.getGrupo().getDocente().getNombre()+"<br/>";
                                        aux += "Grupo: "+gh.getGrupo().getNroGrupo()+"<br/>";
                                        aux += "Aula: "+gh.getAula().getNro()+"<br/>";
                                        aux += "Desc: "+gh.getAula().getDescripcion()+"<br/>";
                                    }
                                }
                            }
                        }
                        if(flag)
                            out.println("<td class='td_decoradoRowspan' align='center' style='background:#E5FFE5'>"+aux+"</td>");
                        else
                            out.println("<td class='td_decoradoRowspan' align='center'>&nbsp;</td>");
                        j++;
                    }
                    out.println("</tr>");
                    i++;
                } // fin for
            }else{
                out.println("<tr class='tr_decoradoRowspan'>");
                out.println("   <td class='td_decoradoRowspan' style='text-align:center;color:red'>No existen periodos del d&iacute;a!</td>");
                out.println("</tr>");
            }
            out.println("        </tbody>");
            out.println("</table>");
            out.close();            
        }catch(DataException e){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaDoc -> verHorarios() e: "+e.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaDoc -> verHorarios() DataException "+e.getMessage());
            PAGE = ERROR_AJAX;
        }catch(Exception ex){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaDoc -> verHorarios() ex: "+ex.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaDoc -> verHorarios() Exception ex: "+ex.getMessage());
            PAGE = ERROR_AJAX;
        }finally{
            SqlManager.closeConexion(c);
        }
    }
    
    private void formKardex() throws DataException{
        // accion = 4 = ver el formulario de kardex
        Connection c = null;
        try{
            c = Conector.getConexion();
            CarreraManager cmanager = ManagerFactory.getCarreraManagerInstance(c);
            List<Carrera> carreras = cmanager.getCarrerasPorEstBasic(s_Estudiante.getIdEstudiante());
            request.setAttribute("carreras", carreras);
            PAGE = "WEB-INF/ESTUDIANTE/infoAcademica/verKardex/verKardex.jsp";
        }catch(DataException e){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> formKardex() e: "+e.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> formKardex() DataException "+e.getMessage());
            PAGE = ERROR_PAGE;
        }catch(Exception ex){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> formKardex() ex: "+ex.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> formKardex() Exception ex: "+ex.getMessage());
            PAGE = ERROR_PAGE;
        }finally{
            SqlManager.closeConexion(c);
        }
    }
    
    public void verKardex()throws DataException{
        // accion = 5 = muestra el kardes por carrera
        PAGE = ""; // funcion ajax
        Connection c = null;
        try{            
            int idCarrera = Integer.parseInt(request.getParameter("idCarrera"));
            String nomCarrera = request.getParameter("nomCarrera");
            c = Conector.getConexion();
            InscritoManager imanager = ManagerFactory.getInscritoManagerInstance(c);
            
            List<Inscrito> inscritos = imanager.getKardex(idCarrera, s_Estudiante.getIdEstudiante());
            
            // IMPRIMIMOS EL RESULTADO DE LA TRANSACCION
            PrintWriter out = response.getWriter();
            out.println("<h2 class='decorado'>Kardex</h2>");
            out.println("<div style='clear:left;color:#004080;margin:3px 0px 3px 0px;font-size: 10px;font-weight: bold'><b>CARRERA:</b> "+nomCarrera+"<br/></div>");
            out.println("<div style='clear:left;color:#004080;margin:3px 0px 3px 0px;font-size: 10px;font-weight: bold'><b>EST.:</b> "+s_Estudiante.getNombre()+" "+s_Estudiante.getApellidoPa()+" "+s_Estudiante.getApellidoMa()+"<br/></div>");
            out.println("<table class='tabla_decorado' style='width: 100%'>");
            out.println("    <thead>");
            out.println("        <tr>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>Nº</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>A&Ntilde;O</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>GESTION</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>NIVEL</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>GRUPO</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>COD. MAT.</th>");
            out.println("            <th width='35%' class='th_decoradoRowspan'>NOMBRE MATERIA</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>T1</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>T2</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>T3</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>NOTA</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>2DA</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>NF</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>RES</th>");
            out.println("        </tr>");
            out.println("    </thead>");
            out.println("    <tbody>");
            int i = 0;
            int j = 0;
            int matAprobados = 0;
            int matReprobadas = 0;
            int numInstancias = 0;
            float promedioGeneral = 0;
            float promedioMatAprobados = 0;
            for(Inscrito ins:inscritos){
                i++;
                out.println("<tr class='tr_decorado'>");
                out.println("    <td class='td_decoradoRowspan' style='text-align: center'>"+i+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+ins.getGestion().getYear()+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+ins.getIdGestion()+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+ins.getAux()+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+ins.getGrupo().getNroGrupo()+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+ins.getIdCarrera()+""+ins.getIdMateria()+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+ins.getMateria().getNombre()+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+((ins.getT1() == -1)?"&nbsp;":ins.getT1())+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+((ins.getT2() == -1)?"&nbsp;":ins.getT2())+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+((ins.getT3() == -1)?"&nbsp;":ins.getT3())+"</td>");
                out.println("    <td class='td_decoradoRowspan'>"+((ins.getNota() == -1)?"&nbsp;":ins.getNota())+"</td>");
                if(ins.getSeg2() > -1){
                    out.println("    <td class='td_decoradoRowspan'>"+ins.getSeg2()+"</td>");
                    numInstancias++;
                }else
                    out.println("    <td class='td_decoradoRowspan'>&nbsp;</td>");
                
                if(ins.getNf() > -1){
                    out.println("    <td class='td_decoradoRowspan'>"+ins.getNf()+"</td>");
                    promedioGeneral += ins.getNf();
                    if(ins.getNf() >= 61)
                        promedioMatAprobados += ins.getNf();
                    j++;
                }else
                    out.println("    <td class='td_decoradoRowspan'>&nbsp;</td>");
                if(ins.isAprobado()){
                    out.println("    <td class='td_decoradoRowspan' style='text-align:center'>A</td>");
                    matAprobados++;
                }else{
                    out.println("    <td class='td_decoradoRowspan' style='text-align:center'>R</td>");
                    matReprobadas++;
                }
                out.println("</tr>");
            }
            if(i == 0){
                out.write("<tr class='tr_decorado'>");
                out.write("     <td class='td_decorado' colspan='14' style='text-align:center'><p style='color:red'>No tiene materias cursadas!<p></td>");
                out.write("</tr>");
            }else{
                promedioGeneral = promedioGeneral/j;
                promedioMatAprobados = promedioMatAprobados/matAprobados;
            }
            out.println("</tbody>");
            out.println("</table><br/>");
            out.println("<center>");
            out.println("<table class='tabla_decorado' style='width: 50%'>");
            out.println("    <thead>");
            out.println("        <tr>");
            out.println("            <th class='th_decoradoRowspan' colspan='2' style='text-align:center'>RESUMEN</th>");
            out.println("        </tr>");
            out.println("       <tr class='tr_decorado'>");
            out.println("           <td class='td_decorado'></b>Materias Cursadas</b></td>");
            out.println("           <td class='td_decorado'>"+i+"</td>");
            out.println("        </tr>");
            out.println("       <tr class='tr_decorado'>");
            out.println("           <td class='td_decorado'></b>Materias Aprobadas</b></td>");
            out.println("           <td class='td_decorado'>"+matAprobados+"</td>");
            out.println("        </tr>");
            out.println("       <tr class='tr_decorado'>");
            out.println("           <td class='td_decorado'></b>Materias Reprobadas</b></td>");
            out.println("           <td class='td_decorado'>"+matReprobadas+"</td>");
            out.println("        </tr>");
            out.println("       <tr class='tr_decorado'>");
            out.println("           <td class='td_decorado'></b>N&uacute;merod de Instancias</b></td>");
            out.println("           <td class='td_decorado'>"+numInstancias+"</td>");
            out.println("        </tr>");
            out.println("       <tr class='tr_decorado'>");
            out.println("           <td class='td_decorado'></b>Promedio General</b></td>");
            out.println("           <td class='td_decorado'>"+UtilTransaccion.redondear(promedioGeneral, 2) +"</td>");
            out.println("        </tr>");
            out.println("       <tr class='tr_decorado'>");
            out.println("           <td class='td_decorado'></b>Promedio Materias Aprobados</b></td>");
            out.println("           <td class='td_decorado'>"+UtilTransaccion.redondear(promedioMatAprobados, 2) +"</td>");
            out.println("        </tr>");
            out.println("    </thead>");
            out.println("    <tbody>");
            out.println("</tbody>");
            out.println("</table><br/>");
            out.println("</center>");
            out.close();
        }catch(DataException e){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> verKardex() DataException "+e.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> verKardex() DataException "+e.getMessage());
            PAGE = ERROR_AJAX;
        }catch(Exception ex){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> verKardex() Exception ex: "+ex.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> verKardex() Exception ex: "+ex.getMessage());
            PAGE = ERROR_AJAX;
        }finally{
            SqlManager.closeConexion(c);
        }
    }
    
    private void formEstadoInscrip() throws DataException{
        // accion = 6 = muestra el formulario para ver el estado de inscripcion
        Connection c = null;
        try{
            c = Conector.getConexion();
            GestionManager gmanager = ManagerFactory.getGestionManagerInstance(c);
            CarreraManager cmanager = ManagerFactory.getCarreraManagerInstance(c);
            List<Carrera> carreras = cmanager.getCarrerasPorEstBasic(s_Estudiante.getIdEstudiante());
            Calendar hoy = Calendar.getInstance();
            int year = hoy.get(Calendar.YEAR) - 15;
            request.setAttribute("carreras", carreras);
            request.setAttribute("gestiones", gmanager.getGestionesBasicByYear(year));
            PAGE = "WEB-INF/ESTUDIANTE/EstadoDeInscrip/estadoInscripcion.jsp";
        }catch(DataException e){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> formEstadoInscrip() e: "+e.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> formEstadoInscrip() DataException "+e.getMessage());
            PAGE = ERROR_PAGE;
        }catch(Exception ex){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> formEstadoInscrip() ex: "+ex.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> formEstadoInscrip() Exception ex: "+ex.getMessage());
            PAGE = ERROR_PAGE;
        }finally{
            SqlManager.closeConexion(c);
        }
    }
    
    public void verEstadoInscrip()throws DataException{// accion = 2 = muestra los horarios
        PAGE = ""; // funcion ajax
        Connection c = null;
        try{            
            int idCarrera = Integer.parseInt(request.getParameter("idCarrera"));
            String nomCarrera = request.getParameter("nomCarrera");
            int idGestion = Integer.parseInt(request.getParameter("idGestion"));
            String nomGestion = request.getParameter("nomGestion");
            
            c = Conector.getConexion();
            InscritoManager imanager = ManagerFactory.getInscritoManagerInstance(c);
            
            List<Inscrito> inscritos = imanager.getEstadoInscripPorGest(idGestion, idCarrera, s_Estudiante.getIdEstudiante());
            
            // IMPRIMIMOS EL RESULTADO DE LA TRANSACCION
            PrintWriter out = response.getWriter();
            out.println("<h2 class='decorado'>Estado de Inscripci&oacute;n Gesti&oacute;n ''"+nomGestion+"''</h2>");
            out.println("<div style='clear:left;color:#004080;margin:3px 0px 3px 0px;font-size: 10px;font-weight: bold'><b>ESPECIALIDAD:</b> "+nomCarrera+"<br/></div>");
            out.println("<table class='tabla_decorado' style='width: 100%'>");
            out.println("    <thead>");
            out.println("        <tr>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>Nº</th>");
            out.println("            <th width='5%' class='th_decoradoRowspan'>GRUPO</th>");
            out.println("            <th width='40%' class='th_decoradoRowspan'>MATERIA</th>");
            out.println("            <th width='10%' class='th_decoradoRowspan'>SIGLA</th>");
            out.println("            <th width='40%' class='th_decoradoRowspan'>DOCENTE</th>");
            out.println("        </tr>");
            out.println("    </thead>");
            out.println("    <tbody>");
            int i = 1;
            for(Inscrito inscr:inscritos){
                out.println("<tr class='tr_decorado'>");
                out.println("    <td class='th_decorado' style='text-align: center'>"+i+"</td>");
                out.println("    <td class='th_decorado'>"+inscr.getGrupo().getNroGrupo()+"</td>");
                out.println("    <td class='th_decorado'>"+inscr.getMateria().getNombre()+"</td>");
                out.println("    <td class='th_decorado'>"+inscr.getMateria().getSigla()+"</td>");
                out.println("    <td class='th_decorado'>"+inscr.getGrupo().getDocente().getNombre()+"</td>");
                out.println("</tr>");
                i++;
            }
            if(i == 1){
                out.write("<tr class='tr_decorado'>");
                out.write("     <td class='td_decorado' colspan='5' style='text-align:center'><p style='color:red'>No tiene materias inscritos para la gesti&oacute;n ''"+nomGestion+"''!<p></td>");
                out.write("</tr>");
            }
            out.println("</tbody>");
            out.println("</table><br/><br/>");
            out.close();            
        }catch(DataException e){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> verEstadoInscrip() e: "+e.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> verEstadoInscrip() DataException "+e.getMessage());
            PAGE = ERROR_AJAX;
        }catch(Exception ex){
            System.out.println(UtilDate.getDateTime()+" InfAcademicaEst -> verEstadoInscrip() ex: "+ex.getMessage());
            request.setAttribute("msgError", UtilDate.getDateTime()+" InfAcademicaEst -> verEstadoInscrip() Exception ex: "+ex.getMessage());
            PAGE = ERROR_AJAX;
        }finally{
            SqlManager.closeConexion(c);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
